package com.xyc.javase.juc.threadtest.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Version 1.0
 * @Author:徐衍程
 * @Date:2022/6/12
 * @Content:
 */
public class CallableTest implements Callable<Integer> {
    public Integer call() {
        return 123;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //与 Runnable 相比，Callable 可以有返回值，返回值通过 FutureTask 进行封装。
        CallableTest mc = new CallableTest();
        FutureTask<Integer> ft = new FutureTask<>(mc);
        Thread thread = new Thread(ft);
        thread.start();
        System.out.println(ft.get());
    }
}